package cz.cvut.fel.gfupan.gui.component;

import cz.cvut.fel.gfupan.gui.Window;
import cz.cvut.fel.gfupan.gui.action.AutoCompleteAction;
import cz.cvut.fel.gfupan.gui.action.AutoCompleteKeyListener;
import cz.cvut.fel.gfupan.gui.util.AutoCompleteItem;
import java.util.List;
import javax.swing.JComboBox;

public class AutoCompleteBox extends JComboBox {

    private List<AutoCompleteItem> listItem = null;
    private JComboBox combo;
    private Window parent;

    public AutoCompleteBox(Window parent, List<AutoCompleteItem> items) {
        this.setEditable(true);
        this.parent = parent;
        this.setSelectedItem("");
        this.combo = this;
        init();
        this.listItem = items;
    }

    private void init() {
        this.getEditor().getEditorComponent().addKeyListener(new AutoCompleteKeyListener(parent, this));
        this.addActionListener(new AutoCompleteAction(this));
    }

    public JComboBox getCombo() {
        return combo;
    }

    public List<AutoCompleteItem> items() {
        return this.listItem;
    }

    public Window getWindow() {
        return parent;
    }
}
